package com.scapegoat.pay.web.boss.controller.account;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.scapegoat.pay.common.core.page.PageBean;
import com.scapegoat.pay.common.core.page.PageParam;
import com.scapegoat.pay.account.service.api.RpAccountHistoryService;
import com.scapegoat.pay.account.service.api.RpAccountService;
import com.scapegoat.pay.account.service.entity.RpAccount;
import com.scapegoat.pay.account.service.entity.RpAccountHistory;
import com.scapegoat.pay.user.service.api.RpUserInfoService;
import com.scapegoat.pay.user.service.entity.RpUserInfo;


/**
 * 账户信息
 *
 * @author walkman
 * @date 2017年10月18日 21:42:35
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private RpAccountService rpAccountService;

    @Autowired
    private RpUserInfoService rpUserInfoService;
    
    @Autowired
    private RpAccountHistoryService rpAccountHistoryService;

    /**
     * 函数功能说明 ： 查询账户信息
     *
     * @return String
     * @throws
     * @参数： @return
     */
    @RequestMapping(value = "/list", method = {RequestMethod.POST, RequestMethod.GET})
    public String list(RpAccount rpAccount, PageParam pageParam, Model model) {
        PageBean pageBean = rpAccountService.listPage(pageParam, rpAccount);
        List<Object> recordList = pageBean.getRecordList();
        for (Object obj : recordList) {
            RpAccount account = (RpAccount) obj;
            RpUserInfo userInfo = rpUserInfoService.getDataByMerchentNo(account.getUserNo());
            account.setUserName(userInfo.getUserName());
        }
        model.addAttribute("pageBean", pageBean);
        model.addAttribute("pageParam", pageParam);
        model.addAttribute("rpAccount", rpAccount);
        return "account/list";
    }

    /**
     * 函数功能说明 ： 查询账户历史信息
     *
     * @return String
     * @throws
     * @参数： @return
     */
    @RequestMapping(value = "/historyList", method = {RequestMethod.POST, RequestMethod.GET})
    public String historyList(RpAccountHistory rpAccountHistory, PageParam pageParam, Model model) {
        PageBean pageBean = rpAccountHistoryService.listPage(pageParam, rpAccountHistory);
        List<Object> recordList = pageBean.getRecordList();
        for (Object obj : recordList) {
            RpAccountHistory history = (RpAccountHistory) obj;
            RpUserInfo userInfo = rpUserInfoService.getDataByMerchentNo(history.getUserNo());
            history.setUserName(userInfo.getUserName());
        }
        model.addAttribute("pageBean", pageBean);
        model.addAttribute("pageParam", pageParam);
        model.addAttribute("rpAccountHistory", rpAccountHistory);
        return "account/historyList";
    }
}
